function CategoriesFilter(fromCookie) {

	var self = this;
	this.idsMap = {};

	if(fromCookie) {
		var cookie = $.cookie('trFilterCategories');
		if(cookie != null) {
			var cookieIds = JSON.parse(cookie);
			if($.isArray(cookieIds)) {
				$.each(cookieIds, function (index, categoryId) {
					self.idsMap[categoryId] = categoryId;
				});
			}
		}
	}

	this.set = function(categoryIdsMap) {
		this.idsMap = categoryIdsMap;
		this.onChange();
	};

	this.setIds = function(categoryIds) {
		this.idsMap = {};
		$.each(categoryIds, function(index, categoryId) {
			self.idsMap[categoryId] = categoryId;
		});
		this.onChange();
	};

	this.add = function(categoryId) {
		if(!(categoryId in this.idsMap)) {
			this.idsMap[categoryId] = categoryId;
			this.onChange();
			return true;
		}
	};

	this.remove = function(categoryId) {
		if(categoryId in this.idsMap) {
			delete this.idsMap[categoryId];
			this.onChange();
			return true;
		}
		return false;
	};

	this.onChange = function() {
		$.cookie('trFilterCategories', JSON.stringify(Object.keys(this.idsMap)));
		$(this).trigger('change');
	};

	this.filter = function(categoriesMap) {
		$.each(Object.keys(this.idsMap), function(index, id) {
			if(!(id in categoriesMap)) {
				delete this.idsMap[id];
			}
		});
	};
/*
	this.getIds = function() {
		return Object.keys(this.idsMap);
	};
*/
	this.getValue = function() {
		return Object.keys(this.idsMap);
	};
};